package com.theta.gateway.infra.common.swagger.config;

import io.swagger.annotations.ApiOperation;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;

/**
 *
 * @author theta
 * @date 2020-06-01
 */
@Configuration
@EnableSwagger2WebFlux
//@EnableSwagger2
//@EnableOpenApi
@Profile({"dev","test","release"})
public class SwaggerConfig {
	
	
 
    
    
    @Bean
    public Docket apiDocket(SwaggerProperties properties) {
        if (properties == null) {
            properties = new SwaggerProperties();
        }
        return (new Docket(DocumentationType.SWAGGER_2))
                .apiInfo(this.apiInfo(properties))
                .groupName(properties.getTitle())
                .enable(properties.isEnableSwagger())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("com.gbs.saas.gateway.facade")).paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(SwaggerProperties properties) {
        return (new ApiInfoBuilder())
                .title(properties.getTitle())
                .description(properties.getDescription())
                .contact(new Contact(properties.getAuthor(), (String) null, properties.getEmail()))
                .version(properties.getVersion()).build();
    }
 
    

    
}
